const app = getApp();
var global_data = []
let myFunTimer = null,
    showCount = 0
Page({
    data: {
        showCommenStatus: false,
        pageNum: 1,
        pageSize: 9,
        statusHeight: 0,
        statusHeightStyle: '',
        navHeight: 0,
        tabIndex: 0,
        //是否显示顶部导航栏
        showTabStatus: false,
        allFoodClassify: [],
        foodRecommendVOList: [],
        //百科tab
        classifyTabIndex: 0,
        foodClassifyId: 0,
        activeClassifyTabIndexName: '',
        //视频评论
        reviewList: [],
        getReviewDetail: {},
        //发表内容
        reviewContent: '',
        //避免重复评论
        clickStatus: true,
        tabName: '',
        isShare: false,
        isLinkCopyStatus: false,
        shortLinkData: '',
        //是否点击遮罩层关闭弹框
        closeOverLay: true,
        //swiper 下标
        swiperIndex: 0,
        //定位是否是最后一个视频
        lastVideoStatus: false,
        //组件状态
        lastCurrent: 0,
        //不刷新onshow
        refreshOnShowStatus: false,
        isOverShare: true,
        shortVideoId: 0,
        //评论数据
        commonDetail: {},
        //分享详情
        curQueueDetail: {},
        //定位机型
        platform: '',
        //优先级
        zIndex: 0,
        //是否执行onhide
        openModulesHide: true,
        // swiper
        current: 0,
        videoList: [

        ],
        //是否允许请求数据
        videoStatus: true,
        //是否显示商品
        shopShowStatus: true,
        //显示评论弹窗
        isCommom: false,
        //聚焦
        inputFocus: false,
        //分享图片
        imageTempPath: '',
        //是否衔接滑动
        circular: false,
        //最后一次点击时间
        touchStartTime: 0,
        touchEndTime: 0,
        lastTapTime: 0,
        lastTapTimeoutFunc: null,
        //是否显示右侧栏
        rightNavStatus: true,
        //是否允许点击视频播放与暂停
        videoClickStatus: false,
        //评论数据加载中
        reviewStatus: true,
        //是否关闭了本页面
        isOnhideStatus: false,
        //是否有视频数据
        noDataStatus: false,
        //是否允许点击视频暂停与播放操作
        clickVideoTapStatus: false,
        //原生跳转页面是否关闭视频播放
        isIutoPauseIfNavigate: true,
        //当前播放视频地址
        videoUrl: []
    },
    onLoad(options) {
        this.navHeight()
        //如果是分享页进来的
        if (options && options.id) {
            console.log("如果是分享页进来的", options.id)
            this.setData({
                shortVideoId: options.id
            })
        }
    },
    navHeight() {
        const that = this;
        let systemInfo = wx.getSystemInfoSync();
        let rect = wx.getMenuButtonBoundingClientRect ? wx.getMenuButtonBoundingClientRect() : null; //胶囊按钮位置信息
        wx.getMenuButtonBoundingClientRect();
        let gap = ''; //胶囊按钮上下间距 使导航内容居中
        let width = 0;
        // width 胶囊的宽度，android大部分96，ios为88
        if (systemInfo.platform === 'android') {
            gap = 8;
            width = 96;
        } else if (systemInfo.platform === 'devtools') {
            if (systemInfo.platform == 'ios') {
                gap = 5.5; //开发工具中ios手机
            } else {
                gap = 7.5; //开发工具中android和其他手机
            }
        } else {
            gap = 4;
            width = 88;
        }
        if (!systemInfo.statusBarHeight) {
            //开启wifi的情况下修复statusBarHeight值获取不到
            systemInfo.statusBarHeight = systemInfo.screenHeight - systemInfo.windowHeight - 20;
        }
        // console.log('rect', rect, 2 * gap + rect.height);
        let sysinfo = wx.getSystemInfoSync(),
            statusHeight = sysinfo.statusBarHeight;
        that.setData({
            statusHeight,
            statusHeightStyle: statusHeight + 'px',
            navHeight: (2 * gap) + rect.height,
            //定位机型
            platform: systemInfo.platform
        })
        //47
        // console.log("statusHeight", statusHeight)
        //40
        // console.log("navHeight", this.data.navHeight)
    },
    onShow() {
        //显示视频组件
        if (this.data.isOnhideStatus) {
            this.setData({
                isOnhideStatus: false
            })
        }
        if (this.data.tabIndex == 0) {
            this.getShortVideo(2)
        }
        // console.log("this.data.tabIndex", this.data.tabIndex)
    },
    getUserInfoByCode() {
        const that = this

    },
    myFun2(time) {
        return new Promise((resolve) => {
            myFunTimer = setTimeout(() => {
                resolve(time)
            }, time)
        })
    },
    async getShortVideo(type) {
        const that = this
        const {
            tabIndex,
            platform
        } = that.data
        let pages = getCurrentPages()
        let currPage = pages[pages.length - 1]; //当前页面
        // if (currPage.route != '/videoSwitch/videoSwitch') return;
        if (type != 1 && tabIndex == 0) {
            let param;
            //是否是定位ID的视频
            if (that.data.shortVideoId != 0) {
                param = {
                    shortVideoId: that.data.shortVideoId,
                    //滑动类型 0下滑 1上滑 2第一次进入
                    type
                }
                this.setData({
                    shortVideoId: 0
                })
            } else {
                param = {
                    type
                }
            }
            //onhide onunload 不执行
            if (that.data.videoStatus) {
                if (showCount == 0) {
                    // wx.showLoading({
                    //     title: '玩命加载中..',
                    // })
                    // global_data = []
                    that.setData({
                        // videoList: [],
                        // current: 0
                    })
                    await this.myFun2(1600)
                    myFunTimer = null
                    clearTimeout(myFunTimer)
                }
                // return new Promise(resolve => {
                //     common.request(url, param, 'GET').then(res => {
                //         if (res.code == 'SUCCESS') {
                //             res.data.play = false
                //             res.data.name = res.data.name && res.data.name.length >= 30 ? res.data.name.substring(0, 30) + '...' : res.data.name
                //             res.data.commodityName = res.data.commodityName && res.data.commodityName.length >= 10 ? res.data.commodityName.substring(0, 8) + '...' : res.data.commodityName
                //             //swiper开启无限轮播
                //             if (res.data.surplusNumber == 1) {
                //                 that.setData({
                //                     circular: true
                //                 })
                //             }
                //             //是否显示底部商品
                //             if (res.data.commodityId) {
                //                 that.setData({
                //                     shopShowStatus: true
                //                 })
                //             }
                //             if (global_data.length == 0) {
                //                 global_data.push(res.data, {})
                //             } else {
                //                 global_data[global_data.length - 1] = res.data
                //                 if (res.data.surplusNumber > 1) {
                //                     global_data.push({})
                //                 }
                //             }
                //             setTimeout(() => {
                //                 showCount = 1
                //实例，接口获取需要赋值给全局变量global_data，然后再渲染videoList
                const list = [{
                    commodityId: null,
                    commodityImage: null,
                    commodityName: null,
                    commodityType: null,
                    coverImage: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimgessl.kugou.com%2Fstdmusic%2F20211018%2F20211018165118717946.jpg&refer=http%3A%2F%2Fimgessl.kugou.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1665114311&t=b315b0c8bf2e7058827db52becda5f68",
                    hasPraise: false,
                    id: "1566978702590410754",
                    name: "晚风心里吹",
                    play: false,
                    praiseNum: 0,
                    price: null,
                    recommended: true,
                    remark: "晚风心里吹",
                    reviewNum: 0,
                    shortVideoType: "COMMON",
                    showSalesVolume: null,
                    size: 9083,
                    sort: 1,
                    surplusNumber: 14,
                    url: "https://v6.stream.tencentmusic.com/0b5324aheaaa2yakdbnzlnrkdv6dollqa4qa.f140000.mp4?dis_k=8a8666ee6877ce29606650532b6991e9&dis_t=1662522758&local=1&fromtag=1061013",
                }, {
                    commodityId: null,
                    commodityImage: null,
                    commodityName: null,
                    commodityType: null,
                    coverImage: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimgessl.kugou.com%2Fstdmusic%2F20211018%2F20211018165118717946.jpg&refer=http%3A%2F%2Fimgessl.kugou.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1665114311&t=b315b0c8bf2e7058827db52becda5f68",
                    hasPraise: false,
                    id: "1566978702590410754",
                    name: "晚风心里吹",
                    play: false,
                    praiseNum: 0,
                    price: null,
                    recommended: true,
                    remark: "晚风心里吹",
                    reviewNum: 0,
                    shortVideoType: "COMMON",
                    showSalesVolume: null,
                    size: 9083,
                    sort: 1,
                    surplusNumber: 14,
                    url: "https://vd3.bdstatic.com/mda-jgwmdw6m8rip98kt/sc/mda-jgwmdw6m8rip98kt.mp4?v_from_s=hkapp-haokan-hna&auth_key=1662524762-0-0-92ed9ec6898590ac4b92417474c3d2cc&bcevod_channel=searchbox_feed&pd=1&cd=0&pt=3&logid=3362348145&vid=6866897458158289937&abtest=103742_1-104165_1&klogid=3362348145"
                },{
                    commodityId: null,
                    commodityImage: null,
                    commodityName: null,
                    commodityType: null,
                    coverImage: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimgessl.kugou.com%2Fstdmusic%2F20211018%2F20211018165118717946.jpg&refer=http%3A%2F%2Fimgessl.kugou.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1665114311&t=b315b0c8bf2e7058827db52becda5f68",
                    hasPraise: false,
                    id: "1566978702590410754",
                    name: "晚风心里吹",
                    play: false,
                    praiseNum: 0,
                    price: null,
                    recommended: true,
                    remark: "晚风心里吹",
                    reviewNum: 0,
                    shortVideoType: "COMMON",
                    showSalesVolume: null,
                    size: 9083,
                    sort: 1,
                    surplusNumber: 14,
                    url: "https://v6.stream.tencentmusic.com/0b5324aheaaa2yakdbnzlnrkdv6dollqa4qa.f140000.mp4?dis_k=8a8666ee6877ce29606650532b6991e9&dis_t=1662522758&local=1&fromtag=1061013",
                },]
                that.setData({
                    //关闭没有数据标签
                    noDataStatus: false,
                    videoList: list,
                })
                //                 //首次请求两条数据，避免下一条加载卡顿
                //                 if (global_data.length == 2) {
                //                     that.getShortVideo(0)
                //                 }
                console.log("视频数据", that.data.videoList)
                //             }, 200)
                //         } else {
                //             if (res.message && res.message.indexOf('最后一个') >= 0) {
                //                 // common.showToast(res.message, 'none')
                //                 that.setData({
                //                     lastCurrent: global_data.length,
                //                     //定位是否是最后一个视频
                //                     lastVideoStatus: true
                //                 })
                //             } else {
                //                 that.setData({
                //                     noDataStatus: true
                //                 })
                //             }
                //         }
                if (showCount == 0) {
                    wx.hideLoading({
                        success: (res) => {},
                    })
                }
                //         //渲染顶部导航栏，避免首次进来直接点击百科，视频依旧播放问题
                //         that.setData({
                //             showTabStatus: true
                //         })
                //         resolve(global_data[that.data.current])
                //     })
                // })
            } else {
                let videoList = that.data.videoList
                // if (videoList.length > 0 && videoList[that.data.current].url == "") {
                if (videoList.length > 0) {
                    // console.log(videoList[that.data.current].url)
                    // videoList[that.data.current].url = that.data.videoUrl
                    if (platform == 'ios' && videoList[that.data.current].play) {
                        videoList[that.data.current].play = false
                        // console.log("onshow platform", platform)
                    }
                    that.setData({
                        videoList
                    })
                }
            }
        }
    },
    //分享图片生成
    canvas() {
        const self = this;
        // 使用 wx.createContext 获取绘图上下文 context
        const query = wx.createSelectorQuery()
        // 新接口 canvas2d
        query.select('#firstCanvas')
            .fields({
                node: true,
                size: true
            })
            .exec((res) => {
                console.log(res[0].node)
                const canvas = res[0].node
                const ctx = canvas.getContext('2d')
                const dpr = wx.getSystemInfoSync().pixelRatio
                canvas.width = res[0].width * dpr
                canvas.height = res[0].height * dpr
                ctx.scale(dpr, dpr)
                self.saveCanvers(canvas, ctx)
            });

    },
    async saveCanvers(canvas, ctx) {
        const self = this;
        const {
            videoList,
            current,
        } = self.data
        //暂停按钮
        const pauseImg = self.data.imgPath + 'images/farmImage/videoPause.png'
        console.log({
            pauseImg
        })
        console.log("videoList[current] 视频封面图", videoList[current])
        console.log("videoList[current].coverImage 视频封面图", videoList[current].coverImage)
        const width = wx.getSystemInfoSync().screenWidth // 获取设备宽度
        //let ctx = wx.createCanvasContext('firstCanvas', this); /** 创建画布 */
        // 背景色
        // ctx.fillStyle = '#ffffff'
        // ctx.fillRect(0, 0, 375, 120)
        //绘制背景图
        // ctx.drawImage(imgList[0].value.path, 0, 0, wx.getSystemInfoSync().windowWidth, 589);
        await self.downLoadDrow(canvas, ctx, videoList[current].coverImage, 0, 0, 105, 84)
        // const contentImage = (width / 2) - (35 / 2)
        await self.downLoadDrow(canvas, ctx, pauseImg, 42, 32, 18, 18)
        wx.canvasToTempFilePath({
            canvas: canvas,
            // canvasId: 'firstCanvas',
            fileType: 'jpg', //图片的质量，目前仅对 jpg 有效。取值范围为 (0, 1]，不在范围内时当作 1.0 处理。
            success(res) {
                // 获得图片临时路径
                console.log(res, '8520');
                wx.hideLoading({
                    fial: (err) => {}
                })
                self.setData({
                    imageTempPath: res.tempFilePath
                });
                console.log(self.data.imageTempPath)
                // self.saveImg(res.tempFilePath)
            }
        })
    },
    downLoadDrow(canvas, ctx, url, x, y, w, h) {
        return new Promise((resolve, reject) => {
            wx.getImageInfo({
                src: url,
                success: (res) => {
                    const img = canvas.createImage();
                    img.src = res.path; //微信请求返回头像
                    img.onload = () => {
                        // console.log({
                        //     res
                        // })
                        ctx.drawImage(img, x, y, w, h);
                        // img.src = ""
                        resolve()
                    }
                },
                fail: (err) => {
                    // wx.hideLoading()
                    wx.showToast({
                        title: '下载图片失败，请稍后重试',
                        icon: 'none'
                    })
                    reject()
                    return false
                }
            })
        })
    },
    saveImg(path) {
        // wx.hideLoading()
        wx.saveImageToPhotosAlbum({
            filePath: path,
            success: (res) => {
                wx.showToast({
                    title: '已保存到相册',
                    icon: 'success',
                    duration: 2000
                })
            },
            fail: (err) => {
                wx.showToast({
                    title: '保存失败',
                    icon: 'none'
                });
            }
        })
    },
    onShareAppMessage() {

    },
    onHide() {
        const {
            tabIndex
        } = this.data
        //不允许请求数据
        let videoList = this.data.videoList

        if (tabIndex == 0 && videoList.length > 0) {
            videoList[this.data.current].play = false
            global_data[this.data.current].play = false
            // videoList[this.data.current].url = ''
            this.setData({
                videoList
            })
        }
        this.setData({
            videoStatus: false,
            isOnhideStatus: true
        })
    },
    onUnload() {
        // 赋值
        const {
            tabIndex
        } = this.data
        //不允许请求数据
        //切换百科之后，视频暂停，再关闭页面回来视频播放，按钮去除
        let videoList = this.data.videoList
        if (tabIndex == 0 && videoList.length > 0) {
            videoList[this.data.current].play = false
            global_data[this.data.current].play = false
            // videoList[this.data.current].url = ''
            this.setData({
                videoList
            })
        }
        // console.log("onUnload", this.data.videoList)
        this.setData({
            videoStatus: false,
            isOnhideStatus: true
        })
    },
    //百科与视频切换
    tabClick(e) {
        const that = this
        const {
            current,
            platform
        } = that.data
        console.log({
            e
        })
        const {
            index,
            name
        } = e.detail
        let videoList = that.data.videoList
        that.setData({
            tabIndex: index,
            tabName: name
        })
        //百科
        if (index == 1) {
            if (that.data.foodRecommendVOList.length == 0) {
                that.getAllFoodClassify()
            }
            // this.selectComponent('#custom-component').pauseVideo();      
            //切换百科暂停视频    
            // console.log("当前current", current)
            if (platform == 'android') {
                setTimeout(() => {
                    var videoContext = wx.createVideoContext("video_" + current, that);
                    videoContext.pause();
                    videoList[current].play = true
                    global_data[current].play = true
                    // 赋值
                    that.setData({
                        videoList,
                    })
                }, 200)
            }
        } else {
            // console.log("切回视频")
            if (platform == 'ios' || platform == 'devtools') {
                if (videoList[current].play) {
                    setTimeout(() => {
                        var videoContext = wx.createVideoContext("video_" + current, that);
                        videoContext.pause();
                        videoList[current].play = true
                        that.setData({
                            videoList
                        })
                        // console.log("如果ios的视频点击了暂停",videoList[current].play)
                    }, 200)
                }
            }
        }
    },
    //获取所有食养分类
    getAllFoodClassify() {

    },
    //百科跳转
    goPages(e) {
        const {
            url,
            type,
            item
        } = e.currentTarget.dataset

        setTimeout(() => {
            this.setData({
                showCommenStatus: false
            })
        }, 1000)
    },
    //商品切换
    onGoCommdityPage(e) {
        console.log({
            e
        })
        //不执行onhide
        this.setData({
            openModulesHide: false
        })
    },
    //分类切换
    classifyClick(e) {
        const {
            index
        } = e.currentTarget.dataset
        const {
            allFoodClassify,
        } = this.data
        let classifyTabIndex = this.data.classifyTabIndex
        if (classifyTabIndex == index) return
        this.setData({
            pageNum: 1,
            classifyTabIndex: index,
            foodClassifyId: allFoodClassify.foodClassifyList[index].id,
            activeClassifyTabIndexName: allFoodClassify.foodClassifyList[index].name
        })
        console.log("分类切换", this.data.classifyTabIndex)
        //根据食养分类id查询食养推荐
        this.getFoodRecommend()
    },
    getFoodRecommend() {

    },
    //触底
    onBindscrolltolower() {
        // console.log("触底")
        this.setData({
            pageNum: this.data.pageNum + 1
        })
        this.getFoodRecommend()
    },
    //视频上下切换
    async onChange(e) {
        const that = this
        // console.log('onchange', {
        //     e
        // })
        let videoList = that.data.videoList
        //防止轮播疯狂切换
        if (e.detail.source == 'autoplay' || e.detail.source == 'touch') {
            //点了了其他页面之后回来
            //定位到当前下标与数据匹配，如果滑到没有请求数据的哪一项则请求接口
            // console.log(that.data.videoStatus, videoList[e.detail.current])
            //是否显示右侧边栏
            that.setData({
                rightNavStatus: false,
                //不允许点击播放与暂停
                clickVideoTapStatus: false
            })
            if (videoList[videoList.length - 1].surplusNumber != 1) {
                that.setData({
                    videoStatus: true
                })
            } else {
                that.setData({
                    videoStatus: false
                })
            }
            //一开始请求接口，如果每刷到最后一条则请求接口，少于最后一条不请求
            //if (!that.data.lastVideoStatus) {
            // 滑动类型 0下滑 1上滑 2第一次进入
            // console.log("比较大小", that.data.current - e.detail.current)
            let type, pauseIndex;
            //相邻之间相减为1或-1
            if (that.data.current - e.detail.current == -1 || that.data.current - e.detail.current == 1) {
                type = e.detail.current > that.data.current ? 0 : 1;
            } else {
                type = 0;
            }
            that.setData({
                current: e.detail.current
            })
            await that.getShortVideo(type)
            // console.log("是否有数据", {
            //     data
            // })
            //下滑暂停上一个视频播放，上滑暂停下一个视频播放
            if (type == 0) {
                //当衔接滑动时，下滑为第一个时，取最后一项下标
                if (e.detail.current == 0) {
                    pauseIndex = videoList.length - 1
                } else {
                    pauseIndex = e.detail.current - 1
                }
            } else if (type == 1) {
                pauseIndex = e.detail.current + 1
            }
            var videoContextPause = wx.createVideoContext("video_" + pauseIndex, that);
            videoContextPause.pause();
            //如果之前的一项点击了暂停
            if (videoList[pauseIndex].play) {
                videoList[pauseIndex].play = false
                global_data[pauseIndex].play = false
            }
            videoList.map((item, index) => {
                if (item.id == videoList[e.detail.current].id) {
                    // console.log(item.id + "==" + videoList[e.detail.current].id)
                    if (item.play) {
                        item.play = false
                        global_data[e.detail.current].play = false
                    }
                    var videoContext = wx.createVideoContext("video_" + index, that);
                    videoContext.play();
                } else {
                    var videoContext = wx.createVideoContext("video_" + index, that);
                    videoContext.pause();
                }
            })
            that.setData({
                videoList,
                rightNavStatus: true
            })
        }
    },
    //视频动画结束
    onTransition() {
        // console.log("代码714行")
        this.setData({
            videoClickStatus: true,
            reviewList: [],
            getReviewDetail: {}
        })
    },
    //视频出现缓冲时
    onWaiting(e) {},
    //视频元数据加载完成
    onLoadedmetadata(e) {},
    //视频开始或继续播放
    onBindplay(e) {
        // console.log("视频开始或继续播放", e)
        let pages = getCurrentPages()
        let currPage = pages[pages.length - 1]; //当前页面
        if (currPage.route != 'pages/videoSwitch/videoSwitch') return;
        //加载完成之后才让用户点击暂停与播放
        this.setData({
            clickVideoTapStatus: true
        })
    },
    //点击播放与暂停
    videoTap(e) {
        const that = this
        const {
            videoid,
        } = e.currentTarget.dataset
        const {
            current,
            clickVideoTapStatus
        } = that.data
        let videoList = that.data.videoList
        // 控制点击事件在350ms内触发，加这层判断是为了防止长按时会触发点击事件
        // if (that.data.touchEndTime - that.data.touchStartTime < 350) {
        //     // 当前点击的时间
        //     var currentTime = e.timeStamp
        //     var lastTapTime = that.data.lastTapTime
        //     // 更新最后一次点击时间
        //     that.data.lastTapTime = currentTime
        //     // 如果两次点击时间在200毫秒内，则认为是双击事件
        //     if (currentTime - lastTapTime < 200) {
        //         // 双击事件
        //         clearTimeout(that.data.lastTapTimeoutFunc);
        //         console.log("double click")
        //     } else {
        //         that.data.lastTapTimeoutFunc = setTimeout(function () {
        //             // 单击事件
        //             console.log("dan click")
        //         }, 200);
        //     }
        // }
        // console.log("点击视频", videoList)
        // console.log("点击视频", videoList[current])
        if (clickVideoTapStatus) {
            setTimeout(() => {
                videoList.map((item, index) => {
                    if (item.id == videoid) {
                        // console.log("控制播放暂停", videoList[index])
                        if (item.play) {
                            var videoContext = wx.createVideoContext("video_" + index, that);
                            videoContext.play();
                            videoList[current].play = false
                            global_data[current].play = false
                        } else {
                            var videoContext = wx.createVideoContext("video_" + index, that);
                            videoContext.pause();
                            videoList[current].play = true
                            global_data[current].play = true
                        }
                        // 赋值
                        that.setData({
                            videoList
                        })
                    }
                })
            }, 220)
        }
    },
    //关闭底部商品
    closeShopShow() {
        this.setData({
            shopShowStatus: !this.data.shopShowStatus
        })
    },
    //点赞
    collectClick(e) {

    },
    getOneVideo(id, type) {
        const that = this
        let videoList = that.data.videoList
        const {
            current
        } = that.data
        // common.request(url, {}, 'GET').then(res => {
        //     if (res.code == 'SUCCESS') {
        //         // console.log("获取当个视频", res.data)
        //         if (res.data && res.data.commodity) {
        //             res.data.name = res.data.name && res.data.name.length >= 30 ? res.data.name.substring(0, 30) + '...' : res.data.name
        //             res.data.commodity.commodityName = res.data.commodity.commodityName.length >= 10 ? res.data.commodity.commodityName.substring(0, 10) + '...' : res.data.commodity.commodityName;
        //         }
        //         if (res.data.praiseNum < 9999) {
        //             videoList[current].praiseNum = res.data.praiseNum
        //         } else {
        //             videoList[current].praiseNum = '9999+'
        //         }
        //         if (res.data.reviewNum < 9999) {
        //             videoList[current].reviewNum = res.data.reviewNum
        //         } else {
        //             videoList[current].reviewNum = '9999+'
        //         }
        //         that.setData({
        //             videoList,
        //         })
        //         if (type == 'close') {
        //             that.setData({
        //                 showCommenStatus: false,
        //                 rightNavStatus: true
        //             })
        //         }
        //         // console.log("渲染的数据", videoList[current])
        //     }
        // })
    },
    //点击评论
    commonClick(e) {
        const {
            current,
        } = this.data
        let videoList = this.data.videoList
        this.setData({
            showCommenStatus: true,
            commonDetail: videoList[current],
            pageNum: 1,
            reviewList: [],
            getReviewDetail: {},
            //清空发表内容
            reviewContent: "",
            //右侧栏目
            rightNavStatus: false,
            //显示评论数据加载中..
            reviewStatus: true
        })
        // console.log("评论数据", videoList[current])
        this.getReviewList(0)
    },
    getReviewList(type) {
        const {
            videoList,
            pageNum,
            current
        } = this.data
    },
    // 解码emoji表情
    uncodeUtf16: function (str) {
        var reg = /\&#.*?;/g;
        var result = str.replace(reg, function (char) {
            var H, L, code;
            if (char.length == 9) {
                code = parseInt(char.match(/[0-9]+/g));
                H = Math.floor((code - 0x10000) / 0x400) + 0xD800;
                L = (code - 0x10000) % 0x400 + 0xDC00;
                return unescape("%u" + H.toString(16) + "%u" + L.toString(16));
            } else {
                return char;
            }
        });
        return result;
    },
    //评论遮罩层关闭
    onClose() {
        const {
            videoList,
            current
        } = this.data
        //刷新评论个数
        this.getOneVideo(videoList[current].id, 'close')
    },
    //评论下拉
    onScrollToLower() {
        // console.log("触底")
        this.setData({
            pageNum: this.data.pageNum + 1
        })
        this.getReviewList(1)
    },

    //评论点赞/取消
    hasPraiseClick(e) {

    },
    //发表评论点击
    reviewContentClick() {
        this.setData({
            isCommom: true
        })
        setTimeout(() => {
            this.setData({
                inputFocus: true
            })
        }, 400)
    },
    //遮罩层关闭评论
    onCloseCommon() {
        this.setData({
            isCommom: false
        })
    },
    //评论输入框
    reviewContentInput(e) {
        // console.log({e})
        this.setData({
            reviewContent: e.detail.value,
        })
    },
    //发表评论
    addReview() {
        const {
            videoList,
            current,
            reviewContent,
            platform
        } = this.data
        let clickStatus = this.data.clickStatus
        if (!wx.getStorageSync('SESSION').image) return this.setData({
            isLogin: true
        })
        if (reviewContent == '') {
            common.showToast('请先填写内容再提交', 'none')
            return
        }
        let splitContent = this.utf16toEntities(reviewContent)
        if (clickStatus) {
            this.setData({
                clickStatus: false
            })
        }
    },
    // 将emoji表情其转成 base64
    utf16toEntities: function (str) {
        var patt = /[\ud800-\udbff][\udc00-\udfff]/g; // 检测utf16字符正则
        str = str.replace(patt, function (char) {
            var H, L, code;
            if (char.length === 2) {
                H = char.charCodeAt(0); // 取出高位
                L = char.charCodeAt(1); // 取出低位
                code = (H - 0xD800) * 0x400 + 0x10000 + L - 0xDC00; // 转换算法
                return "&#" + code + ";";
            } else {
                return char;
            }
        });
        return str;
    },
    //分享点击
    shareClick() {
        this.setData({
            isShare: true,
        })
        //测试
        this.canvas()
    },
    //关闭小程序链接遮罩层
    closeOverLay() {
        this.setData({
            isLinkCopyStatus: false
        })
    },
})